#ifndef TAG_H
#define TAG_H 1

#include "main.h"
#include "string.h"
#include "dict.h"
#include "reader.h"

#define NC_FILE_SUFFIX "html"
#define GET_ATTR(dict, key, def, attr) attr = (char *) lookup(dict, key); if (attr == NULL) attr = def;

typedef enum __ncattr__ tagType {
  START_ELEM,
  START_TAG,
  END_ELEM,
  END_TAG
} tagType_t;

typedef struct array pdata_arr_t;
typedef struct array tag_arr_t;

typedef struct __ncattr__ parse_data {
  string_t *file_name;
  string_t *html;
  tag_arr_t *tags;
} parse_data_t;

extern char doc_dir[MAXPATHLEN+1];
extern pdata_arr_t *pdata;

#include "var.h"

typedef struct __ncattr__ tag_data {
  size_t idx;
  var_t *var_ptr;
  dict_t *attrs;
} tag_data_t;

#define CUTOUT_WIDTH 15

/* build tag string based on __tagType and set string __str (returns tag string as char *) */
const char *
build_tag_str(const char *__tagName, const tagType_t __tagType, string_t *__str);

/* remove tags in parsed html file (tag position stored in tag data) after scan_tags */
void
remove_tag(string_t *__html, char *__start_ptr, size_t __len);

/* parse html file, stored in elem */
pdata_arr_t *
parse_html(const char *tag_name, const dirlist_elem_t *elem, pdata_arr_t *pdata_ptr);

/* free all memory related to parse data and tag data */
void
free_all_parse_data(pdata_arr_t *pd_ptr);

/* scan all html files in document dir and create parse data and tag data */
bool
init_html(const char *__search_tag);

#endif
